//
//  UIBarButtonItem+Extension.swift
//  LiuWeiBo
//
//  Created by 刘晓晨 on 2017/3/26.
//  Copyright © 2017年 刘晓晨. All rights reserved.
//

import UIKit

extension UIBarButtonItem {
    
    convenience init(titleStr:String ,andTarget:Any? ,imageName: String? = nil,action:Selector?) {
        self.init()
        let button = UIButton()
        
        //设置button
        button.setTitle(titleStr, for: .normal)
        button.setTitleColor(UIColor.darkGray, for: .normal)
        button.setTitleColor(UIColor.orange, for: .highlighted)
        button.titleLabel?.font = UIFont.systemFont(ofSize: 14)
        button.addTarget(andTarget, action: action!, for: .touchUpInside)
        if let imagename = imageName {
            
            button.setImage(UIImage(named: imagename), for: .normal)
        }
        //自动适配
        button.sizeToFit()
        
        //设置给item
        self.customView = button
    }
}
